<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/freedom.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/freedom.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">


  <link rel="manifest" href="/images/manifest.json">


  <meta name="msapplication-config" content="/images/browserconfig.xml">



  <meta name="keywords" content="面试问题,">










<meta name="description" content="Java中的异常Error也是继承自 Throwable!!!* 抛出Error时，(其实与 exception一样)只要有Catch能接住,程序就不会崩！(当然此时catch只能 *用 *catch(Throwable t | Error e)才能catch住！  没catch住当然会崩！)，有finnal语句 final语句一样会执行！ 执行完后程序才会再崩。 异常的体系结构如下：  只要进入">
<meta name="keywords" content="面试问题">
<meta property="og:type" content="article">
<meta property="og:title" content="面试常见问题整理">
<meta property="og:url" content="http://xuren.tech/2019/08/01/面试常见问题整理/index.html">
<meta property="og:site_name" content="Xuren&#39;s Blogs">
<meta property="og:description" content="Java中的异常Error也是继承自 Throwable!!!* 抛出Error时，(其实与 exception一样)只要有Catch能接住,程序就不会崩！(当然此时catch只能 *用 *catch(Throwable t | Error e)才能catch住！  没catch住当然会崩！)，有finnal语句 final语句一样会执行！ 执行完后程序才会再崩。 异常的体系结构如下：  只要进入">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://xuren.tech/2019/08/01/面试常见问题整理/Java%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8.png">
<meta property="og:image" content="http://xuren.tech/2019/08/01/面试常见问题整理/TCP%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png">
<meta property="og:image" content="http://xuren.tech/2019/08/01/面试常见问题整理/String%E5%AF%B9%E8%B1%A1.png">
<meta property="og:image" content="http://xuren.tech/2019/08/01/面试常见问题整理/MySQL_JOIN.png">
<meta property="og:updated_time" content="2019-08-06T06:40:21.086Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="面试常见问题整理">
<meta name="twitter:description" content="Java中的异常Error也是继承自 Throwable!!!* 抛出Error时，(其实与 exception一样)只要有Catch能接住,程序就不会崩！(当然此时catch只能 *用 *catch(Throwable t | Error e)才能catch住！  没catch住当然会崩！)，有finnal语句 final语句一样会执行！ 执行完后程序才会再崩。 异常的体系结构如下：  只要进入">
<meta name="twitter:image" content="http://xuren.tech/2019/08/01/面试常见问题整理/Java%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://xuren.tech/2019/08/01/面试常见问题整理/">



  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/099563b3.js","daovoice")
  daovoice('init', {
      app_id: "099563b3"
    });
  daovoice('update');
  </script>





  <title>面试常见问题整理 | Xuren's Blogs</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Xuren's Blogs</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://xuren.tech/2019/08/01/面试常见问题整理/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Xuren">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/freedom.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Xuren's Blogs">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">面试常见问题整理</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-08-01T13:22:03+08:00">
                2019-08-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/面试问题整理/" itemprop="url" rel="index">
                    <span itemprop="name">面试问题整理</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  4.1k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  16
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Java中的异常"><a href="#Java中的异常" class="headerlink" title="Java中的异常"></a>Java中的异常</h1><p><strong>Error也是继承自 Throwable!!!*</strong></p>
<p><strong>抛出Error时</strong>，(其实<strong>与 exception一样</strong>)<strong>只要有Catch能接住</strong>,<strong>程序就不会崩</strong>！(当然此时<strong>catch只能 *<em>用 *</em>catch(Throwable t | Error e)</strong>才能catch住！  没catch住当然会崩！)，有finnal语句 final语句一样会执行！ 执行完后程序才会再崩。</p>
<p>异常的体系结构如下：</p>
<p><img src="/2019/08/01/面试常见问题整理/Java%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8.png" alt="Java中的异常"></p>
<p>只要进入try-catch-finally块， 任何环境下。 <strong>finally中的语句一定会执行</strong>！</p>
<p><strong>Thorwable类（表示可抛出）</strong>是所有<strong>异常和错误的超类</strong>，两个直接子类为<strong>Error</strong>和<strong>Exception</strong>，分别表示错误和异常。其中异常类Exception又分为运行时异常(RuntimeException)和非运行时异常，  这两种异常有很大的区别，也称之为<strong>不检查异常（Unchecked Exception）</strong>和<strong>检查异常（Checked Exception）</strong>。下面将详细讲述这些异常之间的区别与联系：<br>1、<strong>Error</strong>与<strong>Exception</strong><br>    Error是程序无法处理的错误，它是由JVM产生和抛出的，比如OutOfMemoryError、ThreadDeath等。这些异常发生时，Java虚拟机（JVM）一般会选择线程终止。(<strong>注意:能被catch住不做处理，程序也会正常运行下去</strong>)
    Exception是程序本身可以处理的异常，这种异常分两大类运行时异常和非运行时异常。程序中应当尽可能去处理这些异常。<br><strong>注意：</strong>博主当时的错误也就出在这里   Error是程序无法处理的错误！ 一直是这样认为的，就认为程序只要抛除Error，程序一定会崩。 然而 没想到 抛出的Error也能被catch住。按照 异常的处理规则，<strong>父类是能catch住其子类类型的异常的</strong>！！！ 而不管你是Error还是Exception，Throwable都能接住，因为是 Error与Exception的父类）</p>
<p>2、<strong>运行时异常</strong>和<strong>非运行时异常</strong><br>    <strong>运行时异常</strong>都是RuntimeException类及其子类异常，如NullPointerException、IndexOutOfBoundsException等，这些异常是<strong>不检查异常</strong>，<strong>程序中可以选择捕获处理，也可以不处理</strong>。这些异常一般是由<strong>程序逻辑错误引起</strong>的，程序应该从逻辑角度尽可能避免这类异常的发生。<br>    <strong>非运行时异常</strong>(编译时就能检查出来)是RuntimeException以外的异常，类型上都属于Exception类及其子类。从<strong>程序语法角度讲是必须进行处理的异常</strong>，<strong>如果不处理，程序就不能编译通过</strong>。(通俗点讲，这种异常，ide开发工具一般都会提醒你要catch！)如<strong>IOException</strong>、<strong>SQLException</strong>等以及用户自定义的Exception异常，一般情况下不自定义检查异常。</p>
<p>3、 try、catch、finally三个语句块应注意的问题<br>    <strong>第一</strong>：try、catch、finally三个语句块均不能单独使用，三者可以组成 <strong>try…catch…finally</strong>、<strong>try…catch</strong>、<strong>try…finally</strong>三种结构，<strong>catch语句可以有一个或多个</strong>，<strong>finally语句最多一个</strong>。
    <strong>第二</strong>：<strong>try、catch、finally</strong>三个代码块中变量的作用域为代码块内部，分别独立<strong>而不能相互访问。如果要在三个块中都可以访问，则需要将变量定义到这些块的外面。<br>    第三：</strong>多个<strong><strong>catch</strong></strong>块时候<strong>，最多</strong>只会匹配其中一个异常类且只会执行该<strong><strong>catch</strong></strong>块代码<strong>，而不会再执行其它的catch块，且匹</strong>配<strong><strong>catch</strong></strong>语句的顺序为从上到下，也可能所有的catch都没执行。<br>    <strong>第四：</strong> 先Catch子类异常再Catch父类异常。</p>
<h1 id="TCP三次握手"><a href="#TCP三次握手" class="headerlink" title="TCP三次握手"></a>TCP三次握手</h1><p>三次握手示意图:<br><img src="/2019/08/01/面试常见问题整理/TCP%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.png" alt="TCP三次握手.png"></p>
<p>三次 是确保双方都有接收/发送能力  的最小次数！</p>
<h1 id="Http请求常见状态码"><a href="#Http请求常见状态码" class="headerlink" title="Http请求常见状态码"></a>Http请求常见状态码</h1><table>
<thead>
<tr>
<th></th>
<th>类别</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>1XX</td>
<td>Information（信息性状态码）</td>
<td>请求正在处理</td>
</tr>
<tr>
<td>2XX</td>
<td>Success(成功状态码)</td>
<td>请求正常处理完成</td>
</tr>
<tr>
<td>3XX</td>
<td>Redirection(重定向状态码)</td>
<td></td>
</tr>
<tr>
<td>4XX</td>
<td>Client Error(客户端错误)</td>
<td></td>
</tr>
<tr>
<td>5XX</td>
<td>Server Error(服务器状态码)</td>
<td></td>
</tr>
</tbody></table>
<p>常见几个:（面试备用）<br><strong>200 OK</strong>  请求完全成功                   <strong>204 No Content</strong> (请求成功，但是没有返回任何主体，此时页面不用刷新)<br><strong>301 Moved Permanently</strong>  永久重定向    <strong>302 Found</strong> 临时重定向<br><strong>400 Bad Request</strong> 请求存在语法错误       <strong>401 Unauthorized</strong> 无权访问<br><strong>403 Forbidden</strong> 不允许访问请求的资源    <strong>404 Not Found</strong> 未找到请求页面<br><strong>500 Internal Server Error</strong> 服务器错误     <strong>503 Service Unbelievable</strong> 服务器超负荷 或者 停机维护无法对外界 提供服务你</p>
<h1 id="Http请求种类"><a href="#Http请求种类" class="headerlink" title="Http请求种类"></a>Http请求种类</h1><p>记个五种 先: <strong>GET</strong> <strong>POST</strong> <strong>DELETE</strong> <strong>PUT</strong>  <strong>TRACE</strong>(回显服务器收到的请求，主要用于测试或诊断)  CONNECT</p>
<h1 id="ThreadLocal"><a href="#ThreadLocal" class="headerlink" title="ThreadLocal"></a>ThreadLocal</h1><p> 面试题:确保线程安全 有哪几种方式？</p>
<p>1.尽量使用局部变量(在方法内，也就绝对线程安全啦)<br>2.使用ThreadLocal,为每个线程单独存储变量.<br>(有高手也可以给我补充补充啊，或者执正一下)</p>
<p>ThreadLocal一般称为<strong>线程本地变量，它是一种特殊的线程绑定机制，将变量与线程绑定</strong>在一起，为每一个线程维护一个独立的变量副本。通过ThreadLocal可以将对象的可见范围限制在同一个线程内。</p>
<p>而ThreadLocal将变量绑定在线程上，在一个线程周期内，无论“你身处何地”，只需通过其提供的get方法就可轻松获取到对象。极大地提高了<strong>对于线程级变量的访问便利性</strong>。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//ThreadLocal的set操作</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">set</span><span class="params">(T value)</span> </span>&#123;</span><br><span class="line">    Thread t = Thread.currentThread();<span class="comment">//1.首先获取当前线程对象</span></span><br><span class="line">        ThreadLocalMap map = getMap(t);<span class="comment">//2.获取该线程对象的ThreadLocalMap</span></span><br><span class="line">        <span class="keyword">if</span> (map != <span class="keyword">null</span>)</span><br><span class="line">            map.set(<span class="keyword">this</span>, value);<span class="comment">//如果map不为空，执行set操作，以当前threadLocal对象为                                    key，实际存储对象为value进行set操作</span></span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            createMap(t, value);<span class="comment">//如果map为空，则为该线程创建ThreadLocalMap</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">//ThreadLocal是个入口，真正的变量是绑定在 线程上的</span></span><br></pre></td></tr></table></figure>

<p>Thread类中的定义，每个线程对象都拥有一个<strong>ThreadLocalMap对象</strong>。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">/* ThreadLocal values pertaining to this thread. This map is maintained</span></span><br><span class="line"><span class="comment">     * by the ThreadLocal class. */</span></span><br><span class="line">ThreadLocal.ThreadLocalMap threadLocals = <span class="keyword">null</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">ThreadLocalMap</span> </span>&#123;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * The entries in this hash map extend WeakReference, using</span></span><br><span class="line"><span class="comment">         * its main ref field as the key (which is always a</span></span><br><span class="line"><span class="comment">         * ThreadLocal object).  Note that null keys (i.e. entry.get()</span></span><br><span class="line"><span class="comment">         * == null) mean that the key is no longer referenced, so the</span></span><br><span class="line"><span class="comment">         * entry can be expunged from table.  Such entries are referred to</span></span><br><span class="line"><span class="comment">         * as "stale entries" in the code that follows.</span></span><br><span class="line"><span class="comment">         * 总是以ThreadLocal对象作为key。该key也可能为空，意味着这个key已不再被使用</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">Entry</span> <span class="keyword">extends</span> <span class="title">WeakReference</span>&lt;<span class="title">ThreadLocal</span>&lt;?&gt;&gt; </span>&#123;</span><br><span class="line">            <span class="comment">/** The value associated with this ThreadLocal. */</span></span><br><span class="line">            Object value;</span><br><span class="line"></span><br><span class="line">            Entry(ThreadLocal&lt;?&gt; k, Object v) &#123;</span><br><span class="line">                <span class="keyword">super</span>(k);</span><br><span class="line">                value = v;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>

<p>1.ThreadLocal仅仅是个变量访问的入口；</p>
<p>2.每一个Thread对象都有一个ThreadLocalMap对象，这个ThreadLocalMap持有对象的引用；</p>
<p>3.ThreadLocalMap以当前的threadlocal对象为key，以真正的存储对象为value。get时通过threadlocal实例就可以找到绑定在当前线程上的对象</p>
<h1 id="TOP-K问题"><a href="#TOP-K问题" class="headerlink" title="TOP K问题"></a>TOP K问题</h1><p>方式一：堆排序 (O(n<em>lg(k)))<br>先用前ｋ个元素　构建一个*</em>最小堆**，　接下来就是 堆排序了。最终该堆中的元素 就是top k了。(数据量少 可以)</p>
<h2 id="堆排序：n-logn"><a href="#堆排序：n-logn" class="headerlink" title="堆排序：n logn"></a>堆排序：n logn</h2><p><strong>堆：</strong> 一个<strong>二叉树</strong>：
 <strong>每个结点的值都大于或等于其左右孩子结点的值，称为大顶堆；或者每个结点的值都小于或等于其左右孩子结点的值，称为小顶堆</strong></p>
<p><strong>大顶堆：arr[i] &gt;= arr[2i+1] &amp;&amp; arr[i] &gt;= arr[2i+2]</strong>  </p>
<p><strong>小顶堆：arr[i] &lt;= arr[2i+1] &amp;&amp; arr[i] &lt;= arr[2i+2]</strong>  </p>
<p><strong>基本思路：</strong></p>
<p><strong>a.</strong> <strong>将无需序列构建成一个堆，根据升序降序需求选择大顶堆或小顶堆;</strong></p>
<p><strong>b.</strong> <strong>将堆顶元素与末尾元素交换，将最大元素”沉”到数组末端;</strong></p>
<p><strong>c.重新调整结构，使其满足堆定义，然后继续交换堆顶元素与当前末尾元素，反复执行调整+交换步骤，直到整个序列有序。</strong></p>
<p>（具体构建堆  的过程自行参考算法）</p>
<h2 id="希尔排序"><a href="#希尔排序" class="headerlink" title="希尔排序"></a>希尔排序</h2><p>一句话： <strong>插入排序的改进版</strong>。gap不断缩小 两边交换，最终变为1则排序完成</p>
<h2 id="桶排序"><a href="#桶排序" class="headerlink" title="桶排序"></a>桶排序</h2><p>一个萝卜一个坑，萝卜放在它应该在的坑。<br>(对数据规模小，且数字不大的 数序列 很友好！)</p>
<h1 id="数组中找出两数之和：O-n"><a href="#数组中找出两数之和：O-n" class="headerlink" title="数组中找出两数之和：O(n)"></a>数组中找出两数之和：O(n)</h1><p>关键问题在于找差值的是偶，能O(1)找出想要的数。—-所以，需要借助 (Java)HashMap来进行查找.</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 一遍HashMap，在插入时 就查找</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; nums.length; i++) &#123;</span><br><span class="line">        <span class="keyword">int</span> complement = target - nums[i];</span><br><span class="line">        <span class="keyword">if</span> (map.containsKey(complement)) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">int</span>[map.get(complement)]; <span class="comment">//找到则 直接取出该key的value就行</span></span><br><span class="line">        &#125;</span><br><span class="line">        map.put(nums[i], i); <span class="comment">//没找到就将数据 放入 map即可</span></span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h1 id="String-对象"><a href="#String-对象" class="headerlink" title="String 对象"></a>String 对象</h1><p><img src="/2019/08/01/面试常见问题整理/String%E5%AF%B9%E8%B1%A1.png" alt="String对象"></p>
<p><strong>String s = “abcd”</strong>  与 <strong>String s1 = new String(“abcd”)</strong>  是两种不一样的创建方式</p>
<p>对于<strong>==</strong>，如果作用于<strong>基本数据</strong>类型的变量，则<strong>直接比较其存储的值</strong>是否相等；</p>
<p>如果作用于<strong>引用类型</strong>的变量，则比较的是<strong>所指向的对象</strong>的<strong>地址</strong></p>
<p>（因为 new 生成的是两个对象，其内存地址不同） <strong>所以 str3 != str4</strong></p>
<p><strong>new</strong>出来的字符串和<strong>直接赋值</strong>给变量的字符串存放的位置是不一样的，<strong>前者是在堆</strong>里面，而<strong>后者在常量池</strong>里面</p>
<p><strong>切记：</strong> 通过<strong>new生成的对象</strong>，其<strong>值永远 是不相等的</strong>！</p>
<p>非new生成的，其值均放在常量池！记住这两个重要的区别。</p>
<p>String虽然是一个</p>
<h1 id="int-与-Integer"><a href="#int-与-Integer" class="headerlink" title="int 与 Integer"></a>int 与 Integer</h1><p>int与Integer 用 == 进行比较时，比较的是值！ (非引用值)</p>
<p>Integer 与 Interger用 == 进行比较时，则比较的是 引用值！</p>
<p>Java定义在自动装箱时对于值从<strong>–128 到127</strong> 之间的值，<strong>它们被装箱为 Integer 对象</strong>后，会存在内存中被重用，<strong>始终只存在一个对象</strong>。</p>
<p>但是,<strong>仅限于 非new产生的Integer 对象</strong>，他们会共用一个。 new产生的对象，则 不会去用那些缓存的Integer对象 。 new 与 非new 的Integer用 == 进行比较，永远不同。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">IntegerCache</span> </span>&#123;  <span class="comment">//Integer内部类 </span></span><br><span class="line">                                     <span class="comment">//享元模式 -128~127</span></span><br><span class="line">       <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> low = -<span class="number">128</span>;</span><br><span class="line">       <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> high;</span><br><span class="line">       <span class="keyword">static</span> <span class="keyword">final</span> Integer cache[];</span><br><span class="line"></span><br><span class="line">       <span class="keyword">static</span> &#123;</span><br><span class="line">           <span class="comment">// high value may be configured by property</span></span><br><span class="line">           <span class="keyword">int</span> h = <span class="number">127</span>;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Integer i1 = <span class="number">13</span>;</span><br><span class="line">Integer i2 = Integer.valueOf(<span class="number">13</span>);</span><br><span class="line">Integer i21 = Integer.valueOf(<span class="number">13</span>);</span><br><span class="line">Integer i3 = <span class="keyword">new</span> Integer(<span class="number">13</span>);</span><br><span class="line">Integer i31 = <span class="keyword">new</span> Integer(<span class="number">13</span>);</span><br><span class="line">System.out.println(i1 == i2);  <span class="comment">//true</span></span><br><span class="line">System.out.println(i21 == i2);  <span class="comment">// true   i1 i2 i21 共享同一个 13</span></span><br><span class="line">System.out.println(i3 == i2);  <span class="comment">//false new出来的，完全是一个新对象</span></span><br><span class="line">System.out.println(i3 == i31); <span class="comment">//fasle new出来的，完全是一个新对象</span></span><br><span class="line"></span><br><span class="line">Integer i4 = <span class="number">520</span>;</span><br><span class="line">Integer i5 = Integer.valueOf(<span class="number">520</span>);</span><br><span class="line">Integer i51 = Integer.valueOf(<span class="number">520</span>);</span><br><span class="line">Integer i6 = <span class="keyword">new</span> Integer(<span class="number">520</span>);</span><br><span class="line">System.out.println(i4 == i5); <span class="comment">//fasle</span></span><br><span class="line">System.out.println(i5 == i51); <span class="comment">//false  i4 i5 i51 超过-128~127的范围了，不在共享了</span></span><br><span class="line">System.out.println(i5 == i6); <span class="comment">//false new出来的，当然是完全不同的对象</span></span><br></pre></td></tr></table></figure>

<h1 id="ConcurrentHahMap与-HashMap"><a href="#ConcurrentHahMap与-HashMap" class="headerlink" title="ConcurrentHahMap与 HashMap"></a>ConcurrentHahMap与 HashMap</h1><p>前者大量使用 Unsafe类的操作 <strong>U.compareAndSwapXXX的方法</strong>这个方法是<strong>利用一个CAS算法实现无锁化的修改值的操作</strong>，他可以大大降低锁代理的性能消耗。。</p>
<p>以及分段锁(好像都不是这么说的，只要知道是锁 细化，只锁住链表/红黑树  的开头节点，而非给整个HashMap加锁)</p>
<h1 id="读取文件并将其输入到控制台"><a href="#读取文件并将其输入到控制台" class="headerlink" title="读取文件并将其输入到控制台"></a>读取文件并将其输入到控制台</h1><p><strong>面试时要是写这种，千万 千万 千万 不要</strong>去想什么编码格式， 按普通的写就行了！！！</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">test</span><span class="params">()</span> <span class="keyword">throws</span> FileNotFoundException,IOException </span>&#123;</span><br><span class="line">    FileInputStream fileInputStream = <span class="keyword">new</span> FileInputStream(<span class="string">"1.txt"</span>);</span><br><span class="line">    <span class="keyword">byte</span>[] bytes = <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">1024</span>];</span><br><span class="line">    <span class="keyword">int</span> i;</span><br><span class="line">    <span class="keyword">while</span> ((i = fileInputStream.read(bytes)) != -<span class="number">1</span>)&#123;</span><br><span class="line">        System.out.println(<span class="keyword">new</span> String(bytes,<span class="number">0</span>,i));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//文件放在与src平级的位置即可</span></span><br></pre></td></tr></table></figure>

<h1 id="MySQL的各种JOIN"><a href="#MySQL的各种JOIN" class="headerlink" title="MySQL的各种JOIN"></a>MySQL的各种JOIN</h1><p><strong>inner join    on</strong> ：也就是 默认的join， 查出的是<strong>两边共有</strong>的</p>
<p><strong>left join   on</strong>：以<strong>左边为主</strong>，右边的有些记录可能没有</p>
<p><strong>right join  on</strong>： 以<strong>右边为主</strong>，左边 的有些记录可能没有</p>
<p><strong>full join  on</strong>：<strong>两边全有</strong>！(MySQ不支持， 但是可以通过  <strong>left join+ union+right join</strong>实现.    Oracle支持FUll JOIN)</p>
<p>(不要 把inner  jion 和 full join 记反了)</p>
<p><img src="/2019/08/01/面试常见问题整理/MySQL_JOIN.png" alt="MySQL_JOIN"></p>
<p>##　MySQL求笛卡尔积</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SELECT column_name,...... FROM  tableA  JOIN  tableB;  -- 直接join,不做任何条件 on</span><br><span class="line">-- 等同于 如下</span><br><span class="line">SELECT column_name,.... FROM tableA,tableB [Condition]; - MySQL或默认用第一个同名的字段关联</span><br></pre></td></tr></table></figure>

<p><strong>面试题</strong>:一句sql求 球队的比赛组合.  （很显然，要先得到 笛卡尔积，然后再删选笛卡尔积）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT A.name,B.name FROM table1 A,table2 B  WHERE A.name &gt; B.name;</span><br><span class="line">--  A.name &gt; B.name  筛掉 A.name 和 B.name 一样的组合，同时&gt; 也确定顺序(不能一种组合 出现两次)</span><br></pre></td></tr></table></figure>

<h1 id="MySQL语句的执行顺序"><a href="#MySQL语句的执行顺序" class="headerlink" title="MySQL语句的执行顺序"></a>MySQL语句的执行顺序</h1><p>（From   ON   JOIN）[先确定数据集]  –&gt;  WHERE [筛选符合条件的记录] —&gt; GROUP BY[对记录进行分组] –&gt; SELECT[选出数据] –&gt;  HAVING [筛选GRUOP BY后的结果] –&gt; ORDER BY –&gt;LIMIT</p>
<h1 id="Java中的main函数"><a href="#Java中的main函数" class="headerlink" title="Java中的main函数"></a>Java中的main函数</h1><p><strong>main函数格式固定！</strong> <strong>哪儿都不能改！</strong> 否则程序无法正常启动！！！(要是问你原因，就是jvm就是这么设计的,然后你可以告诉他 可以从盘古开天辟地开始问的 )</p>
<p>main 函数<strong>可以重载</strong>！！！ 可以<strong>自己在里面调用自己</strong>(当然这样会爆栈)！！！</p>
<p>(被个啥奇奇怪怪的面试的问到过这种奇葩问题，真蛋疼………..还有啥 对象和实例 有什么区别？整懵逼了…….阿三和印度的人的区别！)</p>
<h1 id="Java-中传值-OR-传址？"><a href="#Java-中传值-OR-传址？" class="headerlink" title="Java 中传值 OR 传址？"></a>Java 中传值 OR 传址？</h1><p>When you’re passing primitives into a method, you get a distinct copy of the primitive. When you’re passing a reference into a method, you get a copy of the reference.—《Thingking In Java》</p>
<p>Java中传递的永远是 传递对象的副本！</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.xuren.interview;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">StringAndChar</span> </span>&#123;</span><br><span class="line">    String string = <span class="keyword">new</span> String(<span class="string">"good"</span>);</span><br><span class="line">    StringBuilder stringBuilder = <span class="keyword">new</span> StringBuilder(<span class="string">"hello"</span>);</span><br><span class="line">    StringBuilder stringBuilder1 = <span class="keyword">new</span> StringBuilder(<span class="string">"hello1"</span>);</span><br><span class="line">    <span class="keyword">char</span>[] ch=&#123;<span class="string">'a'</span>,<span class="string">'b'</span>,<span class="string">'c'</span>&#125;;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        StringAndChar ex = <span class="keyword">new</span> StringAndChar();</span><br><span class="line">        ex.change(ex.string,ex.ch );</span><br><span class="line">        System.out.println(ex.string+<span class="string">"and"</span>);  <span class="comment">// goodand</span></span><br><span class="line">        System.out.println(ex.ch);<span class="comment">// g bc</span></span><br><span class="line"></span><br><span class="line">        ex.changeBuilder(ex.stringBuilder,ex.stringBuilder1);</span><br><span class="line">        System.out.println(ex.stringBuilder); <span class="comment">// hello are you ok?</span></span><br><span class="line">        System.out.println(ex.stringBuilder1);<span class="comment">// hello1</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">change</span><span class="params">(String s,<span class="keyword">char</span> ch[])</span></span>&#123;</span><br><span class="line">        s = <span class="string">"test ok"</span>;</span><br><span class="line">        ch[<span class="number">0</span>] = <span class="string">'g'</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">changeBuilder</span><span class="params">(StringBuilder s,StringBuilder s1)</span></span>&#123;</span><br><span class="line">        s.append(<span class="string">"are you ok?"</span>);</span><br><span class="line">        s1=s;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//对于所用基本数据与对象，传递的都是 副本！ 在函数内对副本的任何改变 都不会反应到本体上！</span></span><br><span class="line"><span class="comment">//要想让函数达成改变效果(只针对引用)，必须要将 该改变后的副本 传回去！即 一定要有返回值 将这种改变返回！</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/** 特殊情况</span></span><br><span class="line"><span class="comment">*String类，由于其不可变性，就算将 改变后的值返回 以及 调用其内部函数等，原值 也是无法改变的！</span></span><br><span class="line"><span class="comment">*StringBiulder/Buffer以及其他任意对象也是  调用其 内部函数(例如StringBuilder append()函数)等，就算不返回，原值也是可以改变的！</span></span><br><span class="line"><span class="comment">*其他对象也是，调用其内部函数后，就算不返回，一样可以改变本体值！</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>

<h2 id="如何通过-函数交换-两个int数据的值"><a href="#如何通过-函数交换-两个int数据的值" class="headerlink" title="如何通过 函数交换 两个int数据的值"></a>如何通过 函数交换 两个int数据的值</h2><p>目前只想到 投机取巧的方法,将其 封装到 int[] 中作为交换函数的 参数，其他暂时没想到。</p>
<h1 id="POST-与-GET-区别"><a href="#POST-与-GET-区别" class="headerlink" title="POST 与 GET 区别"></a>POST 与 GET 区别</h1><p><a href="https://www.cnblogs.com/mttcug/p/8545837.html" target="_blank" rel="noopener">参考博文</a></p>
<p><strong>大概记住:</strong><br>只要不是密文传输，<strong>没有谁更安全</strong>。 (POST稍微安全，因为参数不会被保存在浏览器历史或 web 服务器日志中。)<br><strong>GET长度</strong>限制 主要是 <strong>URL地址不能过长</strong>。
<strong>POST可传递二进制数据</strong>， GET不能。<br>GET能被收藏，能被作为书签，能被缓存，历史记录可以查到，后退按钮/刷新按钮无害。 但是POST统统不行。</p>
<h1 id="Java中的-父子类继承"><a href="#Java中的-父子类继承" class="headerlink" title="Java中的 父子类继承"></a>Java中的 父子类继承</h1><p>若 子类中有与 父类 同名通类型的成员变量，则使用子类new的对象时， 子类中的该变量会完全取代 父类的该成员变量，且父类的改变量 若没有重新指定值时，该变量也会自动变为NULL。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//父</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Base</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String string = <span class="string">"base"</span>;</span><br><span class="line"></span><br><span class="line">    Base()&#123;</span><br><span class="line">        basePrint();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">basePrint</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        System.out.println(string);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 子</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Sub</span> <span class="keyword">extends</span> <span class="title">Base</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String string = <span class="string">"Sub"</span>;</span><br><span class="line"></span><br><span class="line">    Sub()&#123;</span><br><span class="line">        basePrint();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">basePrint</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        System.out.println(string);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//测试类</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SubTest</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Base a = <span class="keyword">new</span> Sub();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//输出结果:</span></span><br><span class="line"><span class="comment">// null (子类初始化 当然是先初始化父类，父类中与子类同名[只 同名即可]的对象 置为NULL[若子类对象中的 同名变量类型变为 数值类型，则是变为0，父类中该成员变脸 类型不用管！] )</span></span><br><span class="line"><span class="comment">// Sub  (输出子类中的 成员变量的值)</span></span><br></pre></td></tr></table></figure>


      
    </div>
	<div><div>

    <br>
    <br>
    <div style="text-align:left;color: #ccc;font-size:14px;">
	---本文结束<i class="fa fa-paw"></i>感谢您的阅读---
	<br>
	作者：Xuren
	<br>
	<span>发布时间:</span>2019年08月01日 - 13:22:03
	<br>
	<span>最后更新:</span>2019年08月06日 - 14:40:21
	<br>
	本文链接：<a href="/2019/08/01/面试常见问题整理/" title="面试常见问题整理">http://xuren.tech/2019/08/01/面试常见问题整理/</a>
    <br>
	<!--<span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="http://xuren.tech/2019/08/01/面试常见问题整理/"  aria-label="复制成功！"></i></span>
    -->
	版权声明：本文为博主原创文章，转载请附上博文链接！
	</div>
	
	<script> 
    var clipboard = new Clipboard('.fa-clipboard');
    clipboard.on('success', $(function(){
      $(".fa-clipboard").click(function(){
        swal({   
          title: "",   
          text: '复制成功',   
          html: false,
          timer: 500,   
          showConfirmButton: false
        });
      });
    }));  
    </script>

</div>
</div>

    
    
    
	<!-- 新加代码 -->
	<div>
    
        

    
    </div>

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/面试问题/" rel="tag"><i class="fa fa-tag"></i> 面试问题</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/07/31/计算机英语单词学习/" rel="next" title="计算机英语单词学习">
                <i class="fa fa-chevron-left"></i> 计算机英语单词学习
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/08/03/Nginx-CookBook学习——基础/" rel="prev" title="Nginx_CookBook学习——基础">
                Nginx_CookBook学习——基础 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
  <script>
    window._bd_share_config = {
      "common": {
        "bdText": "",
        "bdMini": "1",
        "bdMiniList": false,
        "bdPic": ""
      },
      "image": {
        "viewList": ["tsina", "douban", "sqq", "qzone", "weixin", "twi", "fbook"],
        "viewText": "分享到：",
        "viewSize": "16"
      },
      "slide": {
        "bdImg": "5",
        "bdPos": "left",
        "bdTop": "100"
      }
    }
  </script>

<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>
<!--//bdimg.share.baidu.com-->

      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC80NDQ3MS8yMTAwMw"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/freedom.png" alt="Xuren">
            
              <p class="site-author-name" itemprop="name">Xuren</p>
              <p class="site-description motion-element" itemprop="description">做一条最咸的咸鱼!</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">38</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/xuren11" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:296685262@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Java中的异常"><span class="nav-number">1.</span> <span class="nav-text">Java中的异常</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#TCP三次握手"><span class="nav-number">2.</span> <span class="nav-text">TCP三次握手</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Http请求常见状态码"><span class="nav-number">3.</span> <span class="nav-text">Http请求常见状态码</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Http请求种类"><span class="nav-number">4.</span> <span class="nav-text">Http请求种类</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#ThreadLocal"><span class="nav-number">5.</span> <span class="nav-text">ThreadLocal</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#TOP-K问题"><span class="nav-number">6.</span> <span class="nav-text">TOP K问题</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#堆排序：n-logn"><span class="nav-number">6.1.</span> <span class="nav-text">堆排序：n logn</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#希尔排序"><span class="nav-number">6.2.</span> <span class="nav-text">希尔排序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#桶排序"><span class="nav-number">6.3.</span> <span class="nav-text">桶排序</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#数组中找出两数之和：O-n"><span class="nav-number">7.</span> <span class="nav-text">数组中找出两数之和：O(n)</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#String-对象"><span class="nav-number">8.</span> <span class="nav-text">String 对象</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#int-与-Integer"><span class="nav-number">9.</span> <span class="nav-text">int 与 Integer</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#ConcurrentHahMap与-HashMap"><span class="nav-number">10.</span> <span class="nav-text">ConcurrentHahMap与 HashMap</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#读取文件并将其输入到控制台"><span class="nav-number">11.</span> <span class="nav-text">读取文件并将其输入到控制台</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#MySQL的各种JOIN"><span class="nav-number">12.</span> <span class="nav-text">MySQL的各种JOIN</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#MySQL语句的执行顺序"><span class="nav-number">13.</span> <span class="nav-text">MySQL语句的执行顺序</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Java中的main函数"><span class="nav-number">14.</span> <span class="nav-text">Java中的main函数</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Java-中传值-OR-传址？"><span class="nav-number">15.</span> <span class="nav-text">Java 中传值 OR 传址？</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#如何通过-函数交换-两个int数据的值"><span class="nav-number">15.1.</span> <span class="nav-text">如何通过 函数交换 两个int数据的值</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#POST-与-GET-区别"><span class="nav-number">16.</span> <span class="nav-text">POST 与 GET 区别</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Java中的-父子类继承"><span class="nav-number">17.</span> <span class="nav-text">Java中的 父子类继承</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Xuren</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">63.2k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>








        
<div class="busuanzi-count">
<!--  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
-->
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  









  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  
  


  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
<script type="text/javascript" src="/js/src/clicklove.js"></script>

